package univer.oko.queryAnalizer.sqlEditor;

/**
 * Created by Sergey Kharlamov.
 * Date: 22.07.2006
 * Time: 16:58:12
 */
public class TextInterval implements Comparable {
    /**
     * nachalo intervala
     */
    private int dStart;
    /**
     * oknochanie intervala
     */
    private int dEnd;
    /**
     * uroven' vlozhennosti sootvetstvujuschego bloka
     */
    private int dNestingLevel;

    /**
     * sozdat' novyj interval
     */
    public TextInterval(int pStart, int pEnd, int pNestingLevel) {
        dStart = pStart;
        dEnd = pEnd;
        dNestingLevel = pNestingLevel;
    }

    /**
     * smeschenie pervogo simvola
     */
    public int getStartCharOffset() {
        return dStart;
    }

    /**
     * smeschenie sledujuschego za poslednim simvola
     */
    public int getNextCharOffset() {
        return dEnd;
    }

    /**
     * kolichestvo simvolov v intervale
     */
    public int getLength() {
        return dEnd - dStart;
    }

    /**
     * uroven' vlozhennosti sootvetstvujuschego bloka
     */
    public int getNestingLevel() {
        return dNestingLevel;
    }

    /**
     * prinadlezhit li simvol, zadannyj smescheniem, intervalu
     */
    public boolean inside(int _offset) {
        return (_offset >= dStart) && (_offset < dEnd);
    }

    /**
     * peresekajutsja li dannye intervaly
     */
    public boolean intersects(int _start, int _end) {
        if (_start >= this.dEnd) return false;
        if (_end <= this.dStart) return false;
        return true;
    }

    //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    public int compareTo(Object o) {
        return this.getNestingLevel() - ((TextInterval) o).getNestingLevel();
    }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
